#include "paramadddialog.h"
#include <QBoxLayout>
#include <QLabel>
#include <QLineEdit>
#include <QPushButton>
#include <QMessageBox>
#include <QCloseEvent>

ParamAddDialog::ParamAddDialog(const QStringList& param, QWidget* parent)
	: QDialog(parent), m_param(param)
{
	setStyleSheet("font: 14pt \"Agency FB\"");
	QVBoxLayout* layout = new QVBoxLayout(this);
	QLabel* lable1 = new QLabel(this);
	lable1->setText("请输入以下参数：");
	layout->addWidget(lable1);
	for (auto& iter : param) {
		QLabel* lable = new QLabel(this);
		lable->setText(iter);
		layout->addWidget(lable);
		QLineEdit* edit = new QLineEdit(this);
		m_text.append(edit);
		layout->addWidget(edit);
	}
	QPushButton* button = new QPushButton(this);
	button->setText("设置完成");
	connect(button, &QPushButton::clicked, this, &ParamAddDialog::Button_clicked);
	layout->addWidget(button);
	this->setLayout(layout);
}

ParamAddDialog::~ParamAddDialog()
{}

QStringList ParamAddDialog::GetParam()
{
	QStringList ret;
	for (auto t : m_text) {
		auto str = t->text();
		if (!str.isEmpty()) {
			ret.append(str);
		}
	}


	return ret;
}
void ParamAddDialog::Button_clicked()
{
	int i = 0;
	for (auto t : m_text) {
		auto str = t->text();
		if (str.isEmpty()) {
			QMessageBox::warning(this, "提示", QString("%1不能为空").arg(m_param.at(i)));
			return;
		}
		i++;
	}
	this->done(0);
}

void ParamAddDialog::closeEvent(QCloseEvent* event)
{
	QDialog::closeEvent(event);
}
